package com.han.bom;

/**
 * An abstract class representing a user in the system.
 * This user contains the first name, last name, username, password, and an identifier.
 * Methods in this class allows the user access to the system.
 * 
 * @author Adjell Ian Pabayos
 * 
 * @version 1.0
 * @since JDK 1.7
 * 
 *
 */

public abstract class User {
	private String userID;
	private String firstName;
	private String lastName;
	private String username;
	private String password;
	
	/**
	 * Sole Constructor.
	 * Sets an identifier, but sets all other values to empty
	 * 
	 * @param userID
	 */
	public User(String userID) {
		super();
		this.userID = userID;
	}
	
	/**
	 * Returns the user's ID
	 * 
	 * @return
	 */
	public String getUserID() {
		return userID;
	}
	/**
	 * Sets the user's ID
	 * 
	 * @param userID
	 */
	public void setUserID(String userID) {
		this.userID = userID;
	}
	/**
	 * Returns the user's first name
	 * 
	 * @return
	 */
	public String getFirstName() {
		return firstName;
	}
	/**
	 * Sets the user's first name
	 * 
	 * @param firstName
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	/**
	 * Returns the user's last name
	 * 
	 * @return
	 */
	public String getLastName() {
		return lastName;
	}
	/**
	 * Sets the user's last name
	 * 
	 * @param lastName
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	/**
	 * Returns the user's username
	 * 
	 * @return
	 */
	public String getUsername() {
		return username;
	}
	/**
	 * Sets the user's username
	 * 
	 * @param username
	 */
	public void setUsername(String username) {
		this.username = username;
	}
	/**
	 * Returns the user's password
	 * 
	 * @return
	 */
	public String getPassword() {
		return password;
	}
	/**
	 * Sets the user's password
	 * 
	 * @param password
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	
	/* (non-Javadoc)
	 * Returns a hash code of the object.
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((userID == null) ? 0 : userID.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * Checks if the user being compared is the same as the user it is being compared to.
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (userID == null) {
			if (other.userID != null)
				return false;
		} else if (!userID.equals(other.userID))
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * Returns the User into a string: User [ID, firstname, lastname, username]
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "User [userID=" + userID + ", firstName=" + firstName
				+ ", lastName=" + lastName + ", username=" + username + "]";
	}

	/**
	 * Using an input username and password, checks if the username and password is equal to the values initially set.
	 * Returns true if the values are equal, false if otherwise.
	 * 
	 * @param username - username entered by the user
	 * @param password - password entered by the user
	 * @return
	 */
	@Deprecated
	public boolean validateLogin(String username, String password){
		boolean success = false;
		
		if(username.equals(this.username) && password.equals(this.password)){
			success = true;
		}
		
		return success;
	}
}
